#ifndef _READER_HEADER
#define _READER_HEADER

#include "Book.h"
#include <map>

using namespace std;

class Reader : public Item{
	std::string _name;
	
	// Reader(const Reader&);
	Reader& operator=(const Reader&);
public:
	std::map <std::string, const Book*> _bookList;
	Reader(std::string name) : _name(name){}
	
	void borrow(const Book &book);
	void revert(const Book &book);
	virtual void info();

};

void Reader::borrow(const Book & book){
	map <string, const Book*>::iterator it;
	it = _bookList.find(book.getName());
	if(it != _bookList.end()){
		cout << "You have borrowd this book, please do not borrow again." << endl;
		return;
	}
	_bookList[book.getName()] = &book;
	book.borrow();
}

void Reader::revert(const Book &book){
	map <string, const Book*>::iterator it;
	it = _bookList.find(book.getName());
	if(it == _bookList.end()){
		cout << "You have not borrowed this book." << endl;
		return;
	}
	_bookList.erase(it);

	Book::revert(); // Book.revert() will cause error: C2143: syntax error : missing ';' before '.'
}

void Reader::info(){
	map <string, const Book*>::iterator it = _bookList.begin();
	cout << "Book I have borrowed: " << endl;
	while(it != _bookList.end())
		it++->second->info();
}
#endif // _READER_HEADER